class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            ordernum: '',
            data: "",
            orders:'',
            cateshows:'',
            goodslist:[],
        };
    }

    formatlist(list) {
        var listitem = [], wulist = [],avatarUrl='',nickname='',phone='',{quota,storage}=this.state,fundincome=0,usertotal=0;
        if (list.length > 0) {
        list.forEach((x, i) => {
            let profit=0,redemptionprice=0,bonusprice=0,rewardprice=0,price=0
            let difference=x.newnetworth-x.networth<0?'xy':'dy'
            avatarUrl=x.avatarUrl,nickname=x.nickname,phone=x.phone
            if(x.state=='SHARE_SUCCESS'||x.state=='REDEEM'){
                fundincome+=((x.newnetworth-x.networth)*x.share)
            }
            profit=(((x.newnetworth - x.networth) * x.share)  / 10000).toFixed(2)
            if(x.newnetworth - x.networth>0){
                rewardprice=((parseInt((((x.newnetworth - x.networth) * x.share)*(x.remuneration/10000.00)  / 100)))/100).toFixed(2)
                price=(((x.newnetworth - x.networth) * x.share)*(1-(x.remuneration/10000.00))  / 100.00)
                bonusprice=((parseInt(price))/100).toFixed(2)
            }else if(x.newnetworth - x.networth==0){
                price=0
            }else{
                price=(((x.newnetworth - x.networth) * x.share) / 100.00)
            }
            console.log(price,'priceprice');
            redemptionprice=(((x.total+price)*(x.redemptionrate/10000.00))/100).toFixed(2)
            listitem.push(
                <tr>
                    <td>{getstatecontent(x.state)}</td>
                    <td>{x.ordernum}</td>
                    <td>{x.name}</td>
                    <td>{ x.state == "PAY_SUCCESS"?'0':x.state == "REDEEMED" || x.state == "SOLVED" ? (x.profit / 100).toFixed(2) : profit}</td>
                    <td>{ x.state == "PAY_SUCCESS"?'0':x.state == "REDEEMED" || x.state == "SOLVED" ? (x.bonusprice / 100).toFixed(2) : bonusprice}</td>
                    <td>{ x.state == "PAY_SUCCESS"?'0':x.state == "REDEEMED" || x.state == "SOLVED" ? (x.rewardprice / 100).toFixed(2) : rewardprice}</td>
                    <td>{ x.state == "PAY_SUCCESS"?'0':x.state == "REDEEMED" || x.state == "SOLVED" ? (x.redemptionprice / 100).toFixed(2) : redemptionprice}</td>
                    <td>{(x.total/100).toFixed(2)}</td>
                    <td>{((x.price-x.total)/100).toFixed(2)}</td>
                    <td>{(x.price/100).toFixed(2)}</td>
                    {/* <td className="operatebox">
                        <div className='operate' id={"ope" + x.id}>
                            <div>
                                <img src="./src/todetails.png"/>
                                <p className="edit" onClick={this.todetails.bind(this, x.id,"goods")}>详情</p>
                            </div>
                        </div>
                    </td> */}
                </tr>
            )
        }); }
        else {
            wulist.push(
                <p className="wulist">暂无数据</p>
            )
        }
        fundincome=(fundincome/10000).toFixed(2)
        console.log(quota,storage,fundincome,'fundincomefundincomefundincome');
        usertotal= parseFloat(quota) +parseFloat(storage)+parseFloat(fundincome)
        this.setState({ listitem, list, originallist: list, wulist,avatarUrl,nickname,phone,fundincome,usertotal })
    }




    todetails(e,prop){
        if(prop=="goods"){
            window.location.href = "./goods.html?id="+e;
        }else{
            window.location.href = "./foodsdetails.html?id="+e;
        }
    }
    componentDidMount() {
        let id = GetQueryString('id')
        this.setState({ id }, () => {
            this.freshlist()
        })
    }
    freshlist() {
        let { id } = this.state;
        getuserdetail(id, res => {
            if (res.issuccess == 1) {
                // let {list}=res.list
                this.setState({quota:(res.quota/100).toFixed(2),storage:(res.storage/100).toFixed(2)},()=>{
                    this.formatlist(res.list)
                })
                // this.setState({data:res.data,orders:res.orders,cateshows:res.cateshows},()=>{
                //     this.formatlist(this.state.orders)
                //     this.foodslist(this.state.cateshows)
                // })
            //     createDate = res.data.createDate.replace(/[T]/g, " ")
            //     paytime = res.data.paytime.replace(/[T]/g, " ")
            //     goodsinfo = JSON.parse(res.data.goodsinfo).data
            //     this.formatlist(goodsinfo)
            //     this.setState({ data: res.data, createDate, paytime, goodsinfo,membercategory:res.membercategory,avatarUrl:res.avatarUrl })
            }
        })

    }
    // setpager(pagecount, start) {
    //     let counts = [];
    //     for (let i = 1; i < pagecount + 1; i++) {
    //         counts.push(start + i)
    //     }
    //     this.setState({ counts, pagestart: 0 })
    // }
    // clickpage(e) {
    //     let { start, pagesize,state } = this.state
    //     start = e * pagesize
    //     this.setState({ pagestart: e, start }, () => {
    //         this.freshlist(start,state)
    //     })
    // }
    // setpage(e){
    //     let {pagesize,cid,start}=this.state
    //     pagesize=parseInt(e)
    //     // console.log(pagesize,'pagesizepagesizepagesize');
    //     this.setState({pagesize},()=>{
    //         this.freshlist(start, cid)
    //     })
    // }
    touser() {
        window.location.href = "./user.html";
    }
    render() {
        let { data, listitem,avatarUrl,nickname,phone,quota,storage,fundincome,usertotal} = this.state;

        return (
            <div className="breadLinebox">
                <div className='content_wrap panel-default content_wrap'>
                    <div className="breadLine">
                        <div className="img">
                            <img src='./src/lm_order1.png' />
                            <span onClick={this.touser.bind(this)} style={{ cursor: 'pointer' }}>用户管理</span> > 用户详情
                        </div>
                    </div>
                    <div className="content form">
                        <div className="formtitle">
                        </div>
                        <div className="formbox">
                            <div className="formcontent">
                                 {/* 客户信息 */}
                                 <div>
                                    <div className="ordertitle">
                                        用户信息
                                </div>
                                    <div className="ordercont">
                                        <div className="input-group bz customer">
                                            <img src={avatarUrl} />
                                            <span className="inputcontent">{nickname}</span>
                                        </div>
                                        <div className="input-group bz">
                                            <span className="input-group-addon">联系电话：</span>
                                            <span className="inputcontent">{phone}</span>
                                        </div>
                                        <div className="input-group bz">
                                            <span className="input-group-addon">账户资产：</span>
                                            <span className="inputcontent">{usertotal}</span>
                                        </div>
                                        <div className="input-group bz">
                                            <span className="input-group-addon">可转额度：</span>
                                            <span className="inputcontent">{quota}</span>
                                        </div>
                                        <div className="input-group bz">
                                            <span className="input-group-addon">持有基金：</span>
                                            <span className="inputcontent">{storage}</span>
                                        </div>
                                        <div className="input-group bz">
                                            <span className="input-group-addon">基金收益：</span>
                                            <span className="inputcontent">{fundincome}</span>
                                        </div>
                                        {/* <div className="input-group bz">
                                            <span className="input-group-addon">会员等级：</span>
                                            <span className="inputcontent">{data.membercategory=="0"?"普通会员":data.membercategory}</span>
                                        </div> */}
                                    </div>
                                </div>
                                {/* end 客户信息 */}
                                {/* 订单信息 */}
                                <div>
                                    <div className="ordertitle">
                                    订单信息
                                </div>
                                    <div className="ordercont">
                                        <table className="tab">
                                            <thead>
                                                <tr>
                                                    <th>订单状态</th>
                                                    <th>订单号</th>
                                                    <th>产品名称</th>
                                                    <th>收益</th>
                                                    <th>业绩分红</th>
                                                    <th>业绩报酬</th>
                                                    <th>赎回费用</th>
                                                    <th>购买额度</th>
                                                    <th>购买费用</th>
                                                    <th>合计实付</th>
                                                    {/* <th className="cz tconter">操作</th> */}
                                                </tr>
                                            </thead>
                                            <tbody>
                                                {listitem}
                                            </tbody>
                                        </table>
                                        {/* <div className="pagerbox">
                            <p>共{this.state.total}条</p>
                            <Pager counts={counts} click={this.clickpage.bind(this)} change={this.setpage.bind(this)} index={pagestart} />
                        </div> */}
                                    </div>
                                </div>
                                {/* end 订单信息 */}
                            </div>
                            <div className="submitbox">
                                <button type="button" onClick={this.touser.bind(this)} className="submitbutton">返回</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        )


    }
}





ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='user' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)